<?php
/**
 * Created by JetBrains PhpStorm.
 * User: shaoshuai
 * Date: 11-10-3
 * Time: PM4:03
 */

include_once '../common.func.php';

$categorys = getCategorys();

$id = intval($_POST['id']);
$name = trim($_POST['name']);

if ($_POST['action'] == '保存') {
    if ($categorys[$id]) {
        $categorys[$id]['name'] = $name;
        saveCategorys($categorys);
    }
} elseif ($_POST['action'] == '删除') {
    if (count($categorys[$id]['posts']) == 0) {
        unset($categorys[$id]);
        saveCategorys(array_values($categorys));
    }
} elseif ($_POST['action'] == '添加') {
    array_push($categorys, array('name' => $name, 'posts' => array()));
    saveCategorys($categorys);
}


header('Location: ' . SITE_URL . '/admin/category.php');
